﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3.权限管理
{
    public partial class addTeachers : Form
    {
        public addTeachers()
        {
            InitializeComponent();
        }
        //确定
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string myTeachersID = teachersAdd_ID.Text.Trim(); //学生ID

                DataSet ds = 权限管理.permissionManaging.mySql.sql_search_database("select * from teacherstable "
                    + "where teachersID= '" + myTeachersID + "' ");
                int rowcount = ds.Tables[0].Rows.Count;
                if (rowcount != 0) { MessageBox.Show("ID  have existed"); return; };

                string myTeachersName = teachersAdd_name.Text.Trim(); //学生名字
                string myTeachersPasswd = teachersAdd_passwd.Text.Trim();//学生密码
                string myTeachersPressions = teachersAdd_pressions.Text.Trim(); //权限
                string myTeachersDepartments = teachersAdd_departments.Text.Trim();//院系

                if (myTeachersID == "") { MessageBox.Show("学生ID不能为空！"); return; }
                if (myTeachersName == "") { MessageBox.Show("学生姓名不能为空！"); return; }
                if (myTeachersPasswd == "") { MessageBox.Show("学生密码不能为空！"); return; }
                if (myTeachersPressions == "") { MessageBox.Show("学生权限不能为空！"); return; }
                if (myTeachersDepartments == "") { MessageBox.Show("学生院系不能为空！"); return; }
               
                //插入数据库
                权限管理.permissionManaging.mySql.excute_sql("insert into teacherstable values ('"
                    + myTeachersID + "','"
                    + myTeachersName + "','"
                    + myTeachersPasswd + "','"
                    + myTeachersPressions + "','"
                    + myTeachersDepartments + "')");
                权限管理.permissionManaging.mySql.excute_sql("insert into sqlTableName_and_IDtable values ('"
                   + myTeachersID + "','"
                   + "teacherstable" 
                   +"')");    
                //传递给permissionManaging 学生ID     
                权限管理.permissionManaging.addTeachersInfo_ID = myTeachersID;
                this.Dispose();
            }
            catch
            {
                MessageBox.Show("添加过程中出现错误！");
            }
        }

        //取消
        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
